package org.mm.repository;

import java.util.List;

import org.mm.model.Therapy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
 * TherapyRepository
 *
 * @author Marco Traversari
 * @version $Revision: $ $Date: $ $Author: $
 */
public interface TherapyRepository extends PagingAndSortingRepository<Therapy, Long> {

	@Query("select distinct t from Therapy t left join fetch t.therapyTasks left join fetch t.therapyType where t.patient.id = ?1")
	public List<Therapy> findTherapyByPatientId(Long patientId) throws Exception;

	@Query("select distinct t from Therapy t left join fetch t.therapyTasks left join fetch t.therapyType where t.therapyId = ?1 and t.patient.id = ?2")
	public Therapy findTherapyByIdAndPatientId(Long therapyId, Long patientId) throws Exception;
	

	@Query("select t from Therapy t join fetch t.therapyType where t.patient.id = ?1")
	public Page<Therapy> findTherapyByPatientId(Pageable pageable, Long patientId) throws Exception;
}
